<?php


class tx_zlib_viewhelper_xmlEntities extends tx_zlib_abstract_viewhelper
{

	/**
	 * Generates a XML conform text string
	 *
	 * @param string $string
	 * @param boolean $isHtml
	 * @return string The translated XMl string
	 */
    public function xmlEntities($string, $isHtml=false)
    {
		if($isHtml) {
	        $string = preg_replace('/[^\x09\x0A\x0D\x20-\x7F]/e', '$this->_xmlEntities("$0")', $string);
	      //  $string = preg_replace('/[^\x09\x0A\x0D\x20\x21\x23\x24\x25\x28-\x7F]/e', '$this->_xmlEntities("$0")', $string);
		} else {
		  //$string = preg_replace('/[^\x09\x0A\x0D\x20-\x7F]/e', '$this->_xmlEntities("$0")', $string);
	        $string = preg_replace('/[^\x09\x0A\x0D\x20\x21\x23\x24\x25\x28-\x3B\x3D\x3F-\x7F]/e', '$this->_xmlEntities("$0")', $string);
		}
        return $string;
    }

    /**
     * The internal entity method
     *
     * @param integer $num
     * @return string
     */
    private function _xmlEntities($num)
    {
	    $chars = array(
	        128 => '&#8364;',
	        130 => '&#8218;',
	        131 => '&#402;',
	        132 => '&#8222;',
	        133 => '&#8230;',
	        134 => '&#8224;',
	        135 => '&#8225;',
	        136 => '&#710;',
	        137 => '&#8240;',
	        138 => '&#352;',
	        139 => '&#8249;',
	        140 => '&#338;',
	        142 => '&#381;',
	        145 => '&#8216;',
	        146 => '&#8217;',
	        147 => '&#8220;',
	        148 => '&#8221;',
	        149 => '&#8226;',
	        150 => '&#8211;',
	        151 => '&#8212;',
	        152 => '&#732;',
	        153 => '&#8482;',
	        154 => '&#353;',
	        155 => '&#8250;',
	        156 => '&#339;',
	        158 => '&#382;',
	        159 => '&#376;'
	    );
        $num = ord($num);
        return (($num > 127 && $num < 160) ? $chars[$num] : "&#".$num.";" );
    }

}


if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/zlib/views/helpers/class.tx_zlib_viewhelper_xmlEntities.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/zlib/views/helpers/class.tx_zlib_viewhelper_xmlEntities.php']);
}
